<template>
	<view class="bg-white" style="height: 100vh;">
		<cu-custom bgColor="bg-gradual-orange" :isBack="true" backFlag="navigate">
			<block slot="backText">返回</block>
			<block slot="content">锂电一体机详情</block>
		</cu-custom>
		
			<form>
				<view class="padding flex flex-direction">
					<button class="cu-btn bg-green lg"  @click="openLog">历史数据</button>
				</view>
				
				<view class="cu-form-group">
					<view class="content">
						<text class="text-black title ">设备编号:</text>
					</view>
					<view class="action">
						<text class="text-black title ">{{myFormData.deviceId}}</text>
					</view>
				</view>
				
				<view class="cu-form-group">
					<view class="title">在线状态</view>
					<view class="action">
						<text readonly v-if="annotation.onlineState=='0'" >离线</text>
					</view>
					<view class="action">
						<text readonly v-if="annotation.onlineState=='1'" >在线</text>
					</view>
				</view>
				
				<view class="cu-form-group">
					<view class="content">
						<text class="text-black title ">创建时间:</text>
					</view>
					<view class="action">
						<text class="text-black title ">{{annotation.createtime}}</text>
					</view>
				</view>
				
				<view class="cu-form-group">
					<view class="title">经度</view>
					<input readonly placeholder="" name="input" v-model="annotation.longitude"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">纬度</view>
					<input readonly placeholder="" name="input" v-model="annotation.latitude"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">地理位置</view>
					<textarea readonly placeholder="" name="input" v-model="annotation.address"></textarea>
				</view>
				<view class="cu-form-group" :style="[{animationDelay: '0.2s'}]">
					
					<view style="width: 6rem;">
						<text class="text-black title ">描述:</text>
					</view>
					<view style="">
						<textarea
							style="border:solid 1px #3c9cff; 
							border-radius:8px; 
							resize:none; 
							margin-left: 1rem;
							width: 200px; 
							height:70px;
							overflow:auto;
							font: 14px 正体;
							text-align: left;"
							placeholder-style="position: absolute;left:1.2rem;top:0.7rem" 
							placeholder="" 
							name="input" 
							v-model="myFormData.describe">
						</textarea>
					</view>
				
				</view>
				
				<view class="cu-form-group">
				    <view class="title" >状态更改</view>
					<app-select  placeholder="请选择" :dict="bx_type" v-model="myFormData.status" @change="pickerChange"></app-select>
				</view>
				<view class="padding flex flex-direction">
					<button class="cu-btn bg-green lg" style="background-color:#abc4ff ;"  @click="showjw()">定位采集	</button>
				</view>
				<view class="padding flex flex-direction">
					<button class="cu-btn bg-blue lg"  @click="onSubmit">提交</button>
				</view>
			</form>
	</view>
</template>

<script>

import appSelect from '@/components/my-componets/appSelect.vue'

export default {
	components:{
		appSelect
	 },
	data(){
		return{
			NavBarColor:this.NavBarColor,
			annotation:{
				id:"",
				titile:"",
				startTime:"",
				sender:"",
				msgContent:"",
				recordVideo:"",
				workPic:"",
			},
			myFormData:{
				id:'',
				deviceId:'',//系统设备编号
				deviceCode:'',//中燃设备编号
				equipmentType:'',//设备类型 0：锂电设备 1：阀门井 2:485 市电设备
				projectId:'',//项目id
				projectName:'',//项目名称
				onlineState:'',//在线状态0：离线 1：在线
				malfunctionState:'',//设备状态 0正常 1故障
				newState:'',//新旧状态 0：新设备 1：旧设备
				createtime:'',//创建时间
				describe:'',//描述
				address:'',//地理位置
				longitude:'',//经度
				latitude:'',//纬度
				powersupply:'',//供电情况 0：锂电 1：市电 2：太阳能
				sitetype:'',//站点类型
				catType:'',//cat-1锂电类型：  0：压力 1：流量计 2：压力和流量计
				status:'',
			},
			goodNumber:null,
			flg:true,
			src:"",
			pic:"",
			deviceId:"",
			bx_type: [
				{value:'1',text:"生产发货",},
				{value:'2',text:"未安装"},
				{value:'3',text:"已安装"},
				{value:'4',text:"故障维修"},
				{value:'5',text:"拆回"},
			] ,
			testType:'',
		}
	},

	onLoad: function (option) {
	    const annItem = JSON.parse(decodeURIComponent(option.item));
		this.annotation = annItem 
		this.myFormData = annItem 
		this.src=this.annotation.reportVideo
		this.pic=this.annotation.workPic
		this.deviceId=this.annotation.deviceId
		console.log(this.annotation.recordPic)
	},
	created(){
		console.log("created")
	},
	methods:{
		onSubmit() {
			console.log('myform',this.myFormData)
				
			uni.showModal({
				title: '你好',
				content: this.testType,
				cancelText: '取消',
				confirmText: '确认',
				success: res => {
					if (res.confirm) {
						this.$tip.loading();
						this.$http.put('/two/statusUpdate',this.myFormData).then(res=>{
							console.log(res)
							this.$tip.loaded();
							if (res.data.success){
								this.$tip.toast('提交成功')
								let pages = getCurrentPages(); // 当前页面
								let beforePage = pages[pages.length - 2]; // 上一页
								uni.navigateBack({
								    success: function() {
								        beforePage.onLoad(); // 执行上一页的onLoad方法
								    }
								});
							}
						}).catch(()=>{
							this.$tip.loaded();
							this.$tip.error('提交失败')
						});
						
					}
				}
			})
		},
		pickerChange(e){
			
			this.myFormData.status=e;
			
			for (var i = 0; i < this.bx_type.length; i++) {
				if(this.bx_type[i].value === e){
					// this.bx_type[i].text
					this.testType=`确定要把设备状态更改为\n${this.bx_type[i].text}吗？`;
				}
			}
		},
		showjw() {
			uni.navigateTo({
				url: '/pages/cathode/trapeze?item='+ this.deviceId
			})
		},
		openLog(){
			uni.navigateTo({
				url: '/pages/cathode/lithiumBatteryHis?item='+ encodeURIComponent(JSON.stringify(this.deviceId))
			});
		},
	   showVideo() {
				uni.navigateTo({
					url: '/pages/common/commonVideo?item='+this.src
				}) 
	   }, showPic() {
		   console.log(this.pic)
				uni.navigateTo({
					url: '/pages/common/commonPic?item='+this.pic
				}) 
	   }
	}
}
</script>

<style>
	
</style>
